package com.ruoyi.kjy.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.kjy.domain.HighTechEnterprisesInfo;
import com.ruoyi.kjy.service.HighTechEnterprisesInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

/**
 * 企业Controller
 *
 * @author llr
 * @date 2023-04-27
 */
@RestController
@RequestMapping("/hightechenterprisesinfo")
public class HighTechEnterprisesInfoController extends BaseController {
    @Autowired
    private HighTechEnterprisesInfoService highTechEnterprisesInfoService;

    /**
     * 查询企业列表
     */
    @GetMapping("/list")
    public AjaxResult list(Integer current, Integer size, HighTechEnterprisesInfo highTechEnterprisesInfo) {
        if (Objects.isNull(current)) {
            current = 1;
        }
        if (Objects.isNull(size)) {
            size = 10;
        }
        if (size >= 50) {
            size = 50;
        }
        Page<HighTechEnterprisesInfo> list = highTechEnterprisesInfoService.page(new Page<>(current, size), new LambdaQueryWrapper<HighTechEnterprisesInfo>().setEntity(highTechEnterprisesInfo).orderByAsc(HighTechEnterprisesInfo::getCreateTime));
        return AjaxResult.success(list);
    }


    /**
     * 获取企业详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(highTechEnterprisesInfoService.getById(id));
    }

    /**
     * 新增企业
     */
    @Log(title = "企业", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HighTechEnterprisesInfo highTechEnterprisesInfo) {
        boolean save = highTechEnterprisesInfoService.save(highTechEnterprisesInfo);
        return toAjax(save);
    }

    /**
     * 修改企业
     */
    @Log(title = "企业", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HighTechEnterprisesInfo highTechEnterprisesInfo) {
        return toAjax(highTechEnterprisesInfoService.updateById(highTechEnterprisesInfo));
    }

    /**
     * 删除企业
     */
    @Log(title = "企业", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(highTechEnterprisesInfoService.removeById(ids));
    }
}
